﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CSharp进阶_Dictionary
{
	class Program
	{
		static string ConvertToChinese(int number, Dictionary<int, string> dict)
		{
			StringBuilder res = new StringBuilder();
			while (number != 0)
			{
				res.Append(dict[number % 10]);
				number /= 10;
			}
			int l = 0, r = res.Length - 1;
			while (l < r)
			{
				char temp = res[l];
				res[l] = res[r];
				res[r] = temp;
				l++;
				r--;
			}
			return res.ToString();
		}
		static Dictionary<char, int> Cacl(string word)
		{
			word = word.ToUpper();
			Dictionary<char, int> res = new Dictionary<char, int>();
			foreach (char item in word)
			{
				if (res.ContainsKey(item))
				{
					res[item]++;
				}
				else
				{
					res.Add(item, 1);
				}
			}
			return res;
		}
		static void Main(string[] args)
		{
			Dictionary<char, int> dict = Cacl("Welcome toUnityWorld！");
			foreach (KeyValuePair<char, int> item in dict)
			{
				Console.WriteLine(item.Key + ":" + item.Value);
			}
			//Dictionary<int, string> dict = new Dictionary<int, string>();
			//dict.Add(0, "零");
			//dict.Add(1, "壹");
			//dict.Add(2, "贰");
			//dict.Add(3, "叁");
			//dict.Add(4, "肆");
			//dict.Add(5, "伍");
			//dict.Add(6, "陆");
			//dict.Add(7, "柒");
			//dict.Add(8, "捌");
			//dict.Add(9, "玖");

			//Console.WriteLine(ConvertToChinese(306, dict));
			//Console.WriteLine(ConvertToChinese(11111, dict));
			//#region 声明
			//Dictionary<string, int> dict = new Dictionary<string, int>();
			//#endregion
			//#region 增
			//dict.Add("张三", 1001);
			//dict.Add("李四", 1002);
			//dict.Add("王五", 1003);
			//dict.Add("初音", 1006);
			//#endregion
			//#region 删
			//dict.Remove("王五");
			//#endregion
			//#region 查
			//if (dict.ContainsKey("张三"))
			//{
			//	Console.WriteLine("键查找，找到了 " + dict["张三"]);
			//}
			//else
			//{
			//	Console.WriteLine("键查找，没有找到 张三");
			//}
			//if (dict.ContainsValue(1002))
			//{
			//	Console.WriteLine("值查找，找到了 1002");
			//}
			//else
			//{
			//	Console.WriteLine("值查找，没有找到 1002");
			//}
			//#endregion
			//#region 改
			//dict["张三"] = 1004;
			//#endregion
			//#region 遍历
			//// 1.遍历键
			//foreach (string item in dict.Keys)
			//{
			//	Console.WriteLine(item + ":" + dict[item]);
			//}
			//Console.WriteLine("--------------------------");
			//// 2.遍历值
			//foreach (int item in dict.Values)
			//{
			//	Console.WriteLine(item);
			//}
			//Console.WriteLine("--------------------------");
			//// 3.遍历键值对
			//foreach (KeyValuePair<string, int> item in dict)
			//{
			//	Console.WriteLine(item.Key + ":" + item.Value);
			//}
			//Console.WriteLine("--------------------------");

			//#endregion
		}
	}
}
